import React from 'react';
import '../css/Header.css';
import { useNavigate, useLocation } from 'react-router-dom';

const Header = () => {
  const navigate = useNavigate();
  const location = useLocation();

  // 判断是否为登录页，不显示 Header（可选）
  if (location.pathname === '/login') return null;

  const handleLogout = () => {
    localStorage.removeItem('user');
    navigate('/login');
  };

  const handleProfile = () => {
    navigate('/profile');
  };

  return (
    <header className="header">
      <div className="header-left">
        <img src="/logo.png" alt="logo" className="logo-img" />
        <span className="logo-text">EyeAI 智能眼疾识别系统</span>
      </div>

      <div className="header-right">
        <div className="user-menu">
          <span className="username">admin ▼</span>
          <div className="dropdown">
            <div onClick={handleProfile}>我的资料</div>
            <div onClick={handleLogout}>退出</div>
          </div>
        </div>
      </div>
    </header>
  );
};

export default Header;
